<template>
  <div class="wrapper">
    <!-- header部分 -->
    <header>
      <p>我的订单</p>
    </header>
    <!-- 订单列表部分 -->
    <div class="content">
      <h3 class="order-title">未支付订单信息：</h3>
      <div class="order-card-container">
        <div class="order-card" v-for="item in orderArr" v-if="item.orderState == 0" :key="item.orderId">
          <div class="order-info">
            <p>
              {{item.business.businessName}}
              <i class="fa fa-caret-down" @click="detailetShow(item)"></i>
            </p>
            <div class="order-info-right">
              <p>&#165;{{item.orderTotal}}</p>
              <div class="order-info-right-icon" @click="goToPayment(item)">去支付</div>
            </div>
          </div>
          <ul class="order-detailet" v-show="item.isShowDetailet">
            <li v-for="odItem in item.list">
              <p>{{odItem.foodName}} x {{odItem.quantity}}</p>
              <p>&#165;{{odItem.foodPrice * odItem.quantity}}</p>
            </li>
            <li>
              <p>配送费</p>
              <p>&#165;{{item.business.deliveryPrice}}</p>
            </li>
            <li>
              <p>订单配送至：</p>
              <p>{{ item.deliveryAddress }}</p>
            </li>
          </ul>
        </div>
      </div>
      <h3 class="order-title">已支付订单信息：</h3>
      <div class="order-card-container">
        <div class="order-card" v-for="item in orderArr" v-if="item.orderState == 1" :key="item.orderId">
          <div class="order-info">
            <p>
              {{item.business.businessName}}
              <i class="fa fa-caret-down" @click="detailetShow(item)"></i>
            </p>
            <div class="order-info-right">
              <p>&#165;{{item.orderTotal}}</p>
            </div>
          </div>
          <ul class="order-detailet" v-show="item.isShowDetailet">
            <li v-for="odItem in item.list">
              <p>{{odItem.foodName}} x {{odItem.quantity}}</p>
              <p>&#165;{{odItem.foodPrice * odItem.quantity}}</p>
            </li>
            <li>
              <p>配送费</p>
              <p>&#165;{{item.business.deliveryPrice}}</p>
            </li>
            <li>
              <p>订单配送至：</p>
              <p>{{ item.deliveryAddress }}</p>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- 底部菜单部分 -->
    <Footer></Footer>
  </div>
</template>


<script>
import Footer from '../components/Footer.vue';
import axios from 'axios';

export default {
  name: 'OrderList',
  data() {
    return {
      orderArr: [],
      user: {}
    };
  },
  created() {
    this.fetchOrders();
  },
  methods: {
    detailetShow(orders) {
      orders.isShowDetailet = !orders.isShowDetailet;
    },
    fetchOrders() {
      this.user = this.$getSessionStorage('user');
      this.$axios.get(`/orders/user/${this.user.userId}`)
          .then(response => {
            let result = response.data.data;
            for (let orders of result) {
              orders.isShowDetailet = false;
            }
            this.orderArr = result;
          })
          .catch(error => {
            console.error(error);
          });
    },
    fetchDetail() {
      this.user = this.$getSessionStorage('user');
      this.$axios.get(`/orders/orderDetail/${odItem.orderId}`)
          .then(response => {
            
            for (let orders of result) {
              orders.isShowDetailet = false;
            }
            odItem=response.data.data;
          })
          .catch(error => {
            console.error(error);
          });
    },
    goToPayment(item) {
      this.$router.push({ path: '/payment', query: { orderId: item.orderId } });
    }
  },
  components: {
    Footer
  }
};
</script>
<style scoped>
/****************** 总容器 ******************/
.wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh; /* 将总容器高度设置为视口高度 */
  overflow: hidden; /* 隐藏溢出的内容 */
}

/****************** header部分 ******************/
header {
  width: 100%;
  height: 12vw;
  background-color: #0097FF;
  color: #fff;
  font-size: 4.8vw;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
}

/****************** 内容部分 ******************/
.content {
  flex: 1;
  overflow-y: auto; /* 启用垂直滚动条 */
  margin-top: 12vw; /* 留出 header 的空间 */
  padding-bottom: 16vw; /* 留出 Footer 的空间 */
  padding: 4vw; /* 内容内边距 */
}

/****************** 订单卡片容器 ******************/
.order-card-container {
  display: flex;
  flex-direction: column; /* 改为垂直布局 */
  align-items: center; /* 居中对齐 */
}

/****************** 订单分类标题 ******************/
.order-title {
  width: 100%;
  padding: 1vw 0;
  background-color: #f0f0f0; /* 轻微的灰色背景 */
  border-left: 5px solid #0097FF; /* 蓝色边框 */
  margin: 2vw 0;
  color: #333;
  font-size: 4vw;
  text-align: left;
  padding-left: 4vw; /* 增加左边距 */
  box-sizing: border-box;
}

/****************** 订单卡片 ******************/
.order-card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  width: 90%; /* 调整卡片宽度为90% */
  margin-bottom: 2vw;
  padding: 2vw;
  box-sizing: border-box;
}

.order-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1vw;
}

.order-info-right {
  display: flex;
}

.order-info-right-icon {
  background-color: #f90;
  color: #fff;
  border-radius: 3px;
  margin-left: 2vw;
  user-select: none;
  cursor: pointer;
}

.order-detailet {
  list-style: none;
  padding: 0;
  margin: 0;
}

.order-detailet li {
  padding: 1vw 0;
  font-size: 3vw;
  color: #666;
}
</style>